package com.ysh.xiaomi.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 *
 * 数据源 工具类
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
public class DruidDataSourceUtils {
    private static DruidDataSource dataSource;

    static  {
        try {
            Properties prop = new Properties();
            //获取 属性文件输入流对象
            InputStream is = DruidDataSourceUtils.class.getResourceAsStream("/db.properties");

            prop.load(is);

            dataSource = (DruidDataSource)DruidDataSourceFactory.createDataSource(prop);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() throws SQLException {
        return dataSource.getConnection();
    }

}
